﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>jQuery json省市区街道四级联动地址选择插件</title>

<link rel="stylesheet" type="text/css" href="css/address.css">

</head>
<body>

<label for="Addr" id="areaLabel" class="address">
	<span>所在地区</span>
	<input type="text" name="Addr" id="Addr" readonly placeholder="请选择地区">
</label>
<div id="addressSelectWrapper">
	<div id="addressSelect">
		<div class="tip">
			<h3>所在地区</h3>
			<button type="button" id="cancel"></button>
		</div>
		<div id="address">
			<ul class="selected-address">
				<li class="lastarea" id="lastprovince">请选择</li>
				<li class="lastarea" id="lastcity">请选择</li>
				<li class="lastarea" id="lastarea">请选择</li>
				<li class="lastarea" id="lasttown">请选择</li>
			</ul>
			<div class="address-content">
				<ul id="province"></ul>
				<ul id="city"></ul>
				<ul id="area"></ul>
				<ul id="town"></ul>
			</div>
		</div>
	</div>
</div>

<script src="js/jquery.min.js"></script>
<script src="js/city.js"></script>
<script>
	$(function(){
		// 地址选择器遮罩层打开与关闭
		$("#areaLabel").click(function(e){
			$("#addressSelectWrapper").show();
			e.stopPropagation();
		});
		$(document).click(function () {
			$("#addressSelectWrapper").hide();
		});
		$("#cancel").click(function () {
			$("#addressSelectWrapper").hide();
		});
		$("#addressSelect").click(function (e) {
			e.stopPropagation();
		});

		initAddress();
	});

	//初始化地址选择
	function initAddress() {
		$("#Addr").cityLinkage({
			containerId: 'addressSelectWrapper',
			getSelectedCode:function(){return $("#Addr").data("code");},
			callback:function(data) {
				$("#Addr").val(data.addr).data("code",data.town.code);
			}
		});
	}
</script>
</div>
</body>
</html>